package com.dm.saleassback.common.filter;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @author zx
 * 配置服务器CORS，解决跨域访问问题
 **/

@Configuration
public class CORSFilter extends WebMvcConfigurerAdapter {
    private static final Logger log = LogManager.getLogger(CORSFilter.class);
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        log.info(">>>>>>>>>>>>>>>>>>>>>>>>>CORS<<<<<<<<<<<<<<<<<<<<<<<<");
        registry.addMapping("/**");
    }
    //下面的方式可以实现更细度的访问配置
	/*@Override
    public void addCorsMappings(CorsRegistry registry) {
           registry.addMapping("/api/**")
           .allowedOrigins("http://192.168.1.97")
           .allowedMethods("GET", "POST")
           .allowCredentials(false).maxAge(3600);
    }*/
}
